/********************************************************************
	created:	2011/04/10
	created:	10:4:2011   22:58
	filename: 	d:\Work\Job\trunk\Speed\EventManager.h
	file path:	d:\Work\Job\trunk\Speed
	file base:	EventManager
	file ext:	h
	author:		liang
	
	purpose:	
*********************************************************************/

#ifndef _EventManager_h_2011_04_10_22_58
#define _EventManager_h_2011_04_10_22_58

#include <Qevent.h>
#include "speed.h"
#include <QMutex.h>
#include <QThread.h>

enum TaskMessage
{
	TaskCompletedMsgId  = QEvent::User + 1,
	TaskFileLengthMsgId,
    TaskSpeedChanged,
    TaskFileSizeChanged,
	TaskFileType,
};

class TaskEvent: public QEvent
{
public:
	TaskEvent(TaskMessage eventId, long long guid,bool bSuccess)
		:QEvent((QEvent::Type)(eventId))
	{
		m_TaskGuid = guid;
		m_bSuccess = bSuccess;
	}

	~TaskEvent()
	{

	}

	long long Guid() const
	{
		return m_TaskGuid;
	}

	bool Finish()
	{
		return m_bSuccess;
	}

//private:
	long long m_TaskGuid;
	union
	{
		bool m_bSuccess;
		long long intvalue;
        float floatvalue;
	};	
};

class EventMgr
{
public:
	static EventMgr* GetInstance();
	static void Release();

	bool PushMessage(QEvent* pEvnet);

	void Update();

private:
	EventMgr();
	virtual ~EventMgr();

	static EventMgr* s_pInstance;
	vector<QEvent*> m_EventQue;

    QMutex mutex;

	friend class Speed;
};

#endif

